Need to use the changed directory when using last known project#358
Need to use the changed directory when using last known project#358
Conversation
WalkthroughThe Changes
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/project/project.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Test CLI Upgrade Path (windows-latest)
- GitHub Check: Build and Test (macos-latest)
- GitHub Check: Analyze (go)
| dir = viper.GetString("preferences.project_dir") | ||
| if ProjectExists(dir) { | ||
| tui.ShowWarning("Using your last used project directory (%s). You should change into the correct directory or use the --dir flag.", dir) | ||
| os.Chdir(dir) |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add error handling for the directory change operation.
The os.Chdir(dir) call can fail for various reasons (directory doesn't exist, permission issues, etc.) but the error is not being handled. This could lead to silent failures where the function returns successfully but the working directory change didn't actually occur.
Apply this diff to add proper error handling:
- os.Chdir(dir)
+ if err := os.Chdir(dir); err != nil {
+ logger.Warn("Failed to change to project directory %s: %v", dir, err)
+ tui.ShowBanner("Directory Change Failed", fmt.Sprintf("Could not change to the project directory %s: %v\n\nPlease navigate to the directory manually or use the --dir flag.", dir, err), false)
+ os.Exit(1)
+ }Additionally, consider documenting this side effect in the function's documentation since changing the working directory affects the entire process and could have implications for callers.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| os.Chdir(dir) | |
| if err := os.Chdir(dir); err != nil { | |
| logger.Warn("Failed to change to project directory %s: %v", dir, err) | |
| tui.ShowBanner( | |
| "Directory Change Failed", | |
| fmt.Sprintf( | |
| "Could not change to the project directory %s: %v\n\n"+ | |
| "Please navigate to the directory manually or use the --dir flag.", | |
| dir, | |
| err, | |
| ), | |
| false, | |
| ) | |
| os.Exit(1) | |
| } |
🤖 Prompt for AI Agents
In internal/project/project.go at line 644, the call to os.Chdir(dir) lacks
error handling, which can cause silent failures if changing the directory fails.
Modify the code to capture the error returned by os.Chdir and handle it
appropriately, such as returning the error or logging it. Also, update the
function's documentation to mention that it changes the working directory,
highlighting this side effect for callers.
this can have the effect of using one directory for bundle and another for deploy which can cause a mismatch
Summary by CodeRabbit